const { exec } = require('../db/mysql')
const getList = (author, keyword) => {
    let sql = `select * from blogs where 1=1 `
    if (author) {
        sql += `and author='${author}' `
    }
    if (keyword) {
        sql += `and title like '%${keyword}%' `
    }
    // sql += `order by createtime desc`
    return exec(sql)
}

const getNew = (newblog = {}) => {
    const title = newblog.title
    const content = newblog.content
    const createtime = Date.now()
    const author = newblog.author
    const sql = `insert into blogs(title,content,createtime,author) values('${title}','${content}','${createtime}','${author}')`
    return exec(sql)

}

module.exports = { getList, getNew }